// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.characters;

public class HaloTextHelper {
    public static final HaloTextHelper.ColorRGB COLOR_WHITE = new HaloTextHelper.ColorRGB(255, 255, 255);
    public static final HaloTextHelper.ColorRGB COLOR_GREEN = new HaloTextHelper.ColorRGB(137, 232, 148);
    public static final HaloTextHelper.ColorRGB COLOR_RED = new HaloTextHelper.ColorRGB(255, 105, 97);
    private static String[] queuedLines = new String[4];
    private static String[] currentLines = new String[4];
    private static boolean ignoreOverheadCheckOnce = false;

    public static HaloTextHelper.ColorRGB getColorWhite() {
        return COLOR_WHITE;
    }

    public static HaloTextHelper.ColorRGB getColorGreen() {
        return COLOR_GREEN;
    }

    public static HaloTextHelper.ColorRGB getColorRed() {
        return COLOR_RED;
    }

    public static void forceNextAddText() {
        ignoreOverheadCheckOnce = true;
    }

    public static void addTextWithArrow(IsoPlayer player, String text, boolean arrowIsUp, HaloTextHelper.ColorRGB color) {
        addTextWithArrow(player, text, arrowIsUp, color.r, color.g, color.b, color.r, color.g, color.b);
    }

    public static void addTextWithArrow(IsoPlayer player, String text, boolean arrowIsUp, int r, int g, int b) {
        addTextWithArrow(player, text, arrowIsUp, r, g, b, r, g, b);
    }

    public static void addTextWithArrow(IsoPlayer player, String text, boolean arrowIsUp, HaloTextHelper.ColorRGB color, HaloTextHelper.ColorRGB arrowColor) {
        addTextWithArrow(player, text, arrowIsUp, color.r, color.g, color.b, arrowColor.r, arrowColor.g, arrowColor.b);
    }

    public static void addTextWithArrow(IsoPlayer player, String text, boolean arrowIsUp, int r, int g, int b, int aR, int aG, int aB) {
        addText(
            player,
            "[col="
                + r
                + ","
                + g
                + ","
                + b
                + "]"
                + text
                + "[/] [img=media/ui/"
                + (arrowIsUp ? "ArrowUp.png" : "ArrowDown.png")
                + ","
                + aR
                + ","
                + aG
                + ","
                + aB
                + "]"
        );
    }

    public static void addText(IsoPlayer player, String text, HaloTextHelper.ColorRGB color) {
        addText(player, text, color.r, color.g, color.b);
    }

    public static void addText(IsoPlayer player, String text, int r, int g, int b) {
        addText(player, "[col=" + r + "," + g + "," + b + "]" + text + "[/]");
    }

    public static void addText(IsoPlayer player, String text) {
        int _int = player.getPlayerNum();
        if (!overheadContains(_int, text)) {
            String string = queuedLines[_int];
            if (string == null) {
                string = text;
            } else {
                if (string.contains(text)) {
                    return;
                }

                string = string + "[col=175,175,175], [/]" + text;
            }

            queuedLines[_int] = string;
        }
    }

    private static boolean overheadContains(int _int, String string) {
        if (ignoreOverheadCheckOnce) {
            ignoreOverheadCheckOnce = false;
            return false;
        } else {
            return currentLines[_int] != null && currentLines[_int].contains(string);
        }
    }

    public static void update() {
        for (int _int = 0; _int < 4; _int++) {
            IsoPlayer isoPlayer = IsoPlayer.players[_int];
            if (isoPlayer != null) {
                if (currentLines[_int] != null && isoPlayer.getHaloTimerCount() <= 0.2F * zombie.GameTime.getInstance().getMultiplier()) {
                    currentLines[_int] = null;
                }

                if (queuedLines[_int] != null && isoPlayer.getHaloTimerCount() <= 0.2F * zombie.GameTime.getInstance().getMultiplier()) {
                    isoPlayer.setHaloNote(queuedLines[_int]);
                    currentLines[_int] = queuedLines[_int];
                    queuedLines[_int] = null;
                }
            } else {
                if (queuedLines[_int] != null) {
                    queuedLines[_int] = null;
                }

                if (currentLines[_int] != null) {
                    currentLines[_int] = null;
                }
            }
        }
    }

    public static class ColorRGB {
        public int r;
        public int g;
        public int b;
        public int a = 255;

        public ColorRGB(int _r, int _g, int _b) {
            this.r = _r;
            this.g = _g;
            this.b = _b;
        }
    }
}
